#!/usr/bin/perl
#
# Check a record set to have users before persons
#
use Counter;
use Fcntl;

$users = Counter::open(O_RDWR);

@baddies = $users->selectany("users.f_key from users, persons where
     users.f_key = persons.f_key and persons.f_ctime <> 0 and
     (users.f_ctime > persons.f_ctime or users.f_ctime = 0)");
;
warn "No. of baddies: ", @baddies + 0, "\n";
for $baddy (@baddies) {
    $key = $baddy->{f_key};
    $u = $users->get($key);
    die "No user $key\n" if !$u;
    $p = $u->person();
    print "$key from $$u{f_ctime} to $$p{f_ctime}\n";
    $u->{f_ctime} = $p->{f_ctime};
    # Avoid magic behaviour on store
    bless $u, "FileTable::Record";
    $u->store('NOTEXT');
}   
